package com.ai.pos.client;

import java.util.ArrayList;

import com.ai.pos.client.user.User;
import com.extjs.gxt.desktop.client.Desktop;
import com.extjs.gxt.desktop.client.Shortcut;
import com.extjs.gxt.desktop.client.TaskBar;
import com.extjs.gxt.ui.client.widget.Window;
import com.google.gwt.event.logical.shared.AttachEvent;
import com.google.gwt.event.logical.shared.AttachEvent.Handler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HasHandlers;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Widget;

public class MainDesktop extends Desktop implements IsWidget {

	
	AiCore core;
	
	TaskBar taskMenu;
	ArrayList<Shortcut> shortcuts;
	ArrayList<Window> windows;
	
	Window loginScreen;
	
	
	@Override
	public Widget asWidget() {
		// TODO Auto-generated method stub
		return null;
	}
	
	
	//TODO: make CoreModel, handles applicaiton specific, modular processing. Build menu's, manages cache, user setting etc.
	
	public MainDesktop(AiCore _core)
	{
		core = _core;
		//TODO: Prompt authentication or not, depending on workstation setting
		promptAuthentication();
		
	}
	
	
	private void promptAuthentication() {

		
		loginScreen.show();
		
		//Get user object ready while user is loggin in.
		core.currentUser = new User();
		
	}
	
	private void onSuccessfulAuthentication(String authCodeUsed)
	{
		
		core.currentUser = core.currentUser.load(authCodeUsed);
		
		//Expand "isAdmin" into roles (Default shortcuts, access.)
		if(core.currentUser.isAdmin)
		{
			setDesktopShortcuts(); //This should look at the users preferences, default to certain ones based on role. Admin people get defaulted to admin shortcuts.
			loadStartProgramList();
		}
		else{
			loadPos();
		}
		
	}


	private void loadPos() {
		// TODO Load table commander.
		
	}


	private void loadStartProgramList() {
		// TODO Auto-generated method stub
		
	}


	public void setDesktopShortcuts()
	{
		//FEATURE: Steal Androids idea of onClick show trash to manage shortcut
		
	}
	

	
	
	
	
	
}
